﻿using System;
using System.Collections.Generic;
using System.Text;
using YouHP.BLL;
using YouHP.Model.Group;
using YouHP.Utility;

namespace YouHP.Pages.BBS
{
    public class TopicBasePage:BoardBasePage
    {
        protected string FileRealName = "";
        protected override void ShowPage()
        {
            base.ShowPage();

            if (ErrorCount > 0) return;
            HandleCommon();

        }

        protected TopicInfo TopicData;

        protected void HandleCommon()
        {

            int tid = RequestTools.GetInt("tid", 0);
            if (tid <= 0)
            {
                this.AddErrLine("无效的参数 tid ！");
                return;
            }

            TopicData = TopicBLL.Instance.GetTopicInfo(tid, GroupData.Id);

            if (TopicData.Id <= 0)
            {
                this.AddErrLine("帖子不存在！");
                return;
            }

            string fileName = System.IO.Path.GetFileName(TopicData.TopicFile).ToLower();
            if (!string.IsNullOrEmpty(fileName))
            {
                string[] fileNames = fileName.Split('.');
                string fileEXT = fileNames[fileNames.Length - 1];

                string fileRealNamePrefix = fileNames[fileNames.Length - 2];

                FileRealName = fileRealNamePrefix + "." + fileEXT;
            }


            this.AddLocation(TopicData.Title.Length > 20 ? TopicData.Title.Substring(0, 20) + "..." : TopicData.Title, string.Format("/BBS/Topic.aspx?gid={0}&tid={1}", GroupData.Id, TopicData.Id));




        }
    }
}
